package edu.wpi.cs509.representation;

import java.io.Serializable;

/**
 * Representation of a piece in a game.
 * This class contains all the information on a piece in a game such as Location,
 * Team the piece belongs to, and type of piece.
 *	
 * @author Jay Lubomirski
 * @see edu.wpi.cs509.representation.StrategoPiece
 * @see edu.wpi.cs509.representation.Location
 */
public class PlayerPiece extends StrategoObjectBc implements Serializable, Cloneable{
	private static final long serialVersionUID = 1L; // version of structure for messages
	StrategoPiece pieceType; // type of piece this one is
	TeamColor color; // Team this piece belongs to
	Location location; // Location of this piece
	
	public boolean isClone=false;
	
	/**
	 * Constructor for a piece with no known location.
	 * @param piecetype Type of Piece this is.
	 * @param player Color of player this piece belongs to 
	 */
	public PlayerPiece ( StrategoPiece piecetype, TeamColor player) {
		super(piecetype.toString());
		pieceType = piecetype;
		color = player;
		location = new Location();
	}
	
	/**
	 * Constructor for a piece with a known location.
	 * @param piecetype Type of Piece this is.
	 * @param player Color of player this piece belongs to 
	 * @param loc Location of the piece
	 */
	public PlayerPiece ( StrategoPiece piecetype, TeamColor player, Location loc) {
		super(piecetype.toString());
		pieceType = piecetype;
		color = player;
		location = loc;
	}
	
    protected Object clone(TeamColor mask) throws CloneNotSupportedException {
    	PlayerPiece clonedPiece;
    	Object cloneGb = super.clone();	

    	clonedPiece = (PlayerPiece)cloneGb;
    	clonedPiece.isClone = true;
    	
    	return cloneGb;
    }	
	
	/** 
	 * Return a printable representation of this piece and its location.
	 */
	public String toString() {
		return (getColor().toString() + " " + pieceType + " at " + location);
	}
	
	/**
	 * Return the color of the player this piece belongs to.
	 * @return color of piece
	 */
	public TeamColor getColor() {
		return (color);
	}
	
	/**
	 * Return the rank of this piece.
	 * @return rank of piece, @see StrategoPiece for documentation on rank.
	 */
	public int getRank() {
		return (pieceType.getRank());
	}
	

	/**
	 * Return the type of Stratego piece this is.
	 * @ return - StrategoPiece
	 */
	public StrategoPiece getPieceType() {
		return pieceType;
	}
	
	/** 
	 * 	Determine the maximum theoretical number of spaces this piece could move in a turn.
	 * @return the number of spaces this piece could move
	 */
	public int maxSpacesCanMove() {
		return (pieceType.maxSpacesCanMove());
	}
	
	/** 
	 * Determine if piece can kill a Marshal in an attack.
	 * @return true if piece could kill a Marshal.
	 */
	public boolean canKillaMarshal() {
		return (pieceType.canKillAMarshal());
	}
	
	/**
	 * Determine if piece can distroy a Bomb in an attack.
	 * @return true if piece can destroy a Bomb.
	 */
	public boolean canKillaBomb() {
		return (pieceType.canKillABomb());
	}
	
	/**
	 * Determine if piece is a Marshal
	 * @return true if piece is a Marshal
	 */
	public boolean isaMarshal() {
		return (pieceType == StrategoPiece.MARSHAL);
	}
	
	/**
	 * Determine if piece is a Bomb
	 * @return true if piece is a bomb.
	 */
	public boolean isaBomb() {
		return (pieceType == StrategoPiece.BOMB);
	}
	
	/**
	 * Update the location of this piece.
	 * @param loc new location for the piece
	 */
	public void setLocation(Location loc) {
		location = loc;
	}
	
	/**
	 * Get the location of this piece.
	 */
	public Location getLocation() {
		return location;
	}
	
	/**
	 * Convert the piece type to HIDDEN.
	 */
	public void obfuscate() {
		pieceType = StrategoPiece.HIDDEN;
	}	
}
